package com.earthea.common.util;

import cn.hutool.core.net.NetUtil;
import org.apache.commons.lang3.StringUtils;

/**
 * IP相关工具类
 */
public class IpUtils {
    private static final String LOCAL_IP = loadLocalIp();

    private static String loadLocalIp() {
        return StringUtils.defaultIfBlank(NetUtil.getLocalhostStr(), "127.0.0.1");
    }

    public static String getLocalIp() {
        return LOCAL_IP;
    }

    public static String getHostName() {
        return StringUtils.defaultIfBlank(NetUtil.getLocalHostName(), "localhost");
    }
}
